package com.excesys.exsecs.om.controller;

import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.excel.annotation.ResponseExcel;
import com.excesys.exsecs.common.log.annotation.SysLog;
import com.excesys.exsecs.om.dto.CheckReportStatisticsDto;
import com.excesys.exsecs.om.service.OmICheckSheetService;
import com.excesys.exsecs.om.service.OmInspectionResultService;
import com.excesys.exsecs.om.vo.InspectionVo;
import com.google.common.net.HttpHeaders;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 巡检异常表
 *
 * @author zhangtailong
 * @date 2023-06-20 14:10:58
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/omicheckhome")
@Tag(name = "巡检管理首页")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class OmICheckHomeController {

	// 巡检单
	private final OmICheckSheetService omICheckSheetService;

	// 巡检区域事项结果记录表
	private final OmInspectionResultService omInspectionResultService;

	/**
	 * 巡检全部状态 ------- 首页
	 * @return
	 */
	@Operation(summary = "巡检全部状态", description = "巡检全部状态")
	@SysLog("巡检全部状态")
	@GetMapping("/getAllCheckStatus")
	public R getAllCheckStatus() {
		return R.ok(omICheckSheetService.getAllCheckStatus());
	}

	/**
	 * 巡检完成率 ------- 首页
	 * @return
	 */
	@Operation(summary = "巡检完成率", description = "巡检完成率")
	@SysLog("巡检完成率")
	@GetMapping("/getCheckFinishingRate")
	public R getCheckFinishingRate() {
		return R.ok(omICheckSheetService.getCheckFinishingRate());
	}

	/**
	 * 巡检统计 ------- 首页
	 * @return
	 */
	@Operation(summary = "报修趋势分析", description = "报修趋势分析")
	@SysLog("报修趋势分析")
	@GetMapping("/getCheckRepairAnalyze")
	public R getCheckRepairAnalyze() {
		return R.ok(omICheckSheetService.getCheckRepairAnalyze());
	}

	/**
	 * 【巡检员】巡检报告统计 ------- 首页
	 * @return
	 */
	@Operation(summary = "巡检报告统计", description = "巡检报告统计")
	@SysLog("巡检报告统计")
	@GetMapping("/getCheckReportStatistics/{flag}")
	public R getCheckReportStatistics(@PathVariable("flag") String flag) {
		return R.ok(omICheckSheetService.getCheckReportStatistics(flag));
	}

	/**
	 * 【巡检员】巡检报告统计 ------- 首页
	 * @return
	 */
	@Operation(summary = "巡检报告统计", description = "巡检报告统计")
	@SysLog("巡检报告统计")
	@PostMapping("/getCheckReportStatisticsByDate")
	public R getCheckReportStatisticsByDate(@RequestBody CheckReportStatisticsDto dto) {
		return R.ok(omICheckSheetService.getCheckReportStatisticsByDate(dto));
	}

	/**
	 * 导出excel 表格
	 * @return
	 */

	@Operation(summary = "导出所有数据", description = "导出所有数据")
	@ResponseExcel
	@GetMapping("/export/{flag}")
	// @PreAuthorize("@pms.hasPermission('om_omicheckhome_export')")
	public List<InspectionVo> export(@PathVariable("flag") String flag) {
		return omICheckSheetService.listBamSBuildings(flag);
	}

	/**
	 * 导出excel 表格
	 * @return
	 */

	@Operation(summary = "导出所有数据", description = "导出所有数据")
	@ResponseExcel
	@GetMapping("/getexport/{startTime}/{endTime}")
	// @PreAuthorize("@pms.hasPermission('om_omicheckhome_export')")
	public List<InspectionVo> getexport(@PathVariable("startTime") String startTime,
			@PathVariable("endTime") String endTime) {
		CheckReportStatisticsDto dto = new CheckReportStatisticsDto();
		dto.setStartTime(startTime);
		dto.setEndTime(endTime);
		return omICheckSheetService.listBamSBuildingsByTime(dto);
	}

}
